﻿using System.Net;
using System.Text;
using GC_FFW.SoccerfameParser.Abstractions.Helpers.Validators;
using GC_FFW.SoccerfameParser.Abstractions.Managers;
using GC_FFW.SoccerfameParser.Common;

namespace GC_FFW.SoccerfameParser.Managers
{
	public class WebPageManager : WebPageBaseManager
	{
		#region Variables

		private readonly WebClient _webClient;

		#endregion

		#region Constructors

		public WebPageManager(UrlBaseValidator urlValidator)
			: base(urlValidator)
		{
			_webClient = new WebClient
			{
				Proxy = null,
				Encoding = Encoding.GetEncoding(Constants.UTF8_ENCODING_NAME)
			};
		}

		#endregion

		#region WebPageBaseManager Members

		public override string GetWebPageHtmlMarkup(string pageUrl)
		{
			return UrlValidator.IsValidUrl(pageUrl)
				? _webClient.DownloadString(pageUrl)
				: string.Empty;
		}

		#endregion
	}
}
